define('song',['jquery'],function(){
	var player =document.querySelector("#song_go");//jq对象翻车
	var tubiao=$(".m-song-plybtn");
	var m_song_turn=$(".m-song-turn");
	var timer=setInterval(xz,15);
	var timer2=null;
	var index=0;
	player.play()
	var content_box=document.querySelector(".content_box")
	content_box.addEventListener("click",function(e){
		e.stopPropagation();
		if (player.paused){//暂停状态则播放
            player.play();
            tubiao.css("display","none");
			clearInterval(timer);
			timer2=setInterval(xz,15)
        }else {//播放则暂停
            player.pause();
            tubiao.css("display","block");
            clearInterval(timer);
            clearInterval(timer2);
		}
	})
		
	function xz(){
		index+=0.15;
		m_song_turn.css("transform","rotate("+index+"deg"+")");
	}
//	-------------------------------------------

	var xhr=new XMLHttpRequest;
	var domain="https://www.easy-mock.com/mock/5ab380b6ca15e11ded65b547/wymusic";
	xhr.open("GET",domain+"/lyric");
	xhr.send();
	xhr.addEventListener("readystatechange",function(e){
		if(xhr.readyState==4&&xhr.status==200){
			var obj=JSON.parse(xhr.response);
			var lyric=obj.data[1].lrc.lyric;
			lyric=lyric.replace(/\n/g,"=.=");//换行
			lyric=lyric.split("=.=");
			var lyricArr=[]
			lyric.forEach(function(el,index){
				var obj={};
				obj.time=el.match(/\[(\s)|(\S)*\]/g);
				obj.lyric=el.replace(/\[(\s)|(\S)*\]/g,"").trim();//trim去左右空格
				if(obj.time!=null){
					obj.time=obj.time[0]
				}
				lyricArr.push(obj)
			})
			lyricArr=lyricArr.filter(function(el){
				return el.lyric!=""&&!/a-z/i.test(el.time);
			})
			//输出到页面
			var box=document.querySelector(".geci_box")
			var tmp="";
			lyricArr.forEach(function(el,index){
				tmp+=`<li>${el.lyric}</li>`
			})
			var cdf=document.createDocumentFragment();
			var search_ul=document.createElement("ul");
			search_ul.innerHTML=tmp;
			cdf.appendChild(search_ul);
			box.appendChild(cdf)
			//播放时间动态监听
			var audio=document.querySelector("#song_go")
			var time="";
			audio.addEventListener("timeupdate",function(e){
				time=Math.floor(e.target.currentTime);
				var m=Math.floor(time/60%60);
				var s=time%60;
				if(m<10){
					m="0"+m;
				}
				if(s<10){
					s="0"+s;
				}
				time=m+":"+s;//组装当前时间
				tt()
			})
			var test=[];//这里装的是切割后的时间
			lyricArr.forEach(function(el,index){
				test.push(el.time.slice(1,6));//切割歌词时间
			})
			var geci_li=document.querySelectorAll("ul li")//获取页面所有歌词li
			var change_value=geci_li[0].offsetHeight;
			var step=0;
			function tt(){
				test.forEach(function(el,index){
					if(el==time){
						step=index*change_value;
						var y_zhi="translateY"+"(-"+step+"px)";
						search_ul.style.transform=y_zhi;
						geci_li.forEach(function(el){
							el.classList.remove("geci_active");
						})
						geci_li[index].classList.add("geci_active")
					}
				})
			}
		}
	})
})